package com.bloggers.bodytag;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyContent;
import javax.servlet.jsp.tagext.BodyTagSupport;

public class BodyTagLifecycle extends BodyTagSupport {

	/*@Override
	public int doStartTag() throws JspException
	{
		System.out.println("BodyTagLifecycle.doEndTag()");
		JspWriter out = pageContext.getOut();

		try
		{
			out.println(getBodyContent().getString());
		}
		catch (IOException e)
		{

			e.printStackTrace();
		}

		return SKIP_BODY;
	}
*/
	/*@Override
	public void setBodyContent(BodyContent b)
	{
		super.setBodyContent(b);
	}*/

	/*@Override
	public void doInitBody() throws JspException
	{
		System.out.println("BodyTagLifecycle.doInitBody()");
		super.doInitBody();
	}
*/
	@Override
	public int doAfterBody() throws JspException
	{
		System.out.println("BodyTagLifecycle.doAfterBody()");
		JspWriter out = pageContext.getOut();

		try
		{
			out.println("doAfterBody()"+getBodyContent().getString()+"<br/>");
		}
		catch (IOException e)
		{

			e.printStackTrace();
		}
		return SKIP_BODY;
	}

	@Override
	public int doEndTag() throws JspException
	{
		
		JspWriter out = pageContext.getOut();

		try
		{
			out.println("doEndTag()<br/>"+getBodyContent().getString()+"<br/>");
		}
		catch (IOException e)
		{

			e.printStackTrace();
		}
		return EVAL_PAGE;
	}

}
